From 35be37e8956ab34d8e9efdb7457032556b43f0b6 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 24 May 2020 19:31:08 -0600 Subject: [PATCH] fix -Wstringop-truncation warning in osm. (#568) --- osm.cc | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/osm.cc b/osm.cc index c710b12e5..b7db37769 100644 --- a/osm.cc +++ b/osm.cc @@ -20,11 +20,22 @@ */ +#include // for strlen, strchr, strcmp + +#include // for QByteArray +#include // for QHash +#include // for QLatin1String +#include // for QPair, operator== +#include // for QString, operator+, operator== +#include // for QStringRef +#include // for QVector +#include // for QXmlStreamAttributes +#include // for qPrintable #include "defs.h" -#include "xmlgeneric.h" -#include -#include +#include "gbfile.h" // for gbfprintf, gbfclose, gbfopen, gbfile +#include "src/core/datetime.h" // for DateTime +#include "xmlgeneric.h" // for cb_start, cb_end, xg_callback, xg_string, xg_cb_type, xml_deinit, xml_init, xml_read, xg_tag_mapping static char* opt_tag, *opt_tagnd, *created_by; @@ -40,7 +51,7 @@ static QHash waypoints; static QHash keys; struct osm_icon_mapping_t; -static QHash values; +static QHash, const osm_icon_mapping_t*> values; static QHash icons; static gbfile* fout; @@ -410,20 +421,14 @@ static const osm_icon_mapping_t osm_icon_mappings[] = { static void osm_features_init() { - int i; - /* the first of osm_features is a place holder */ - for (i = 1; osm_features[i]; i++) { - keys.insert(QString::fromUtf8(osm_features[i]), i); + for (int i = 1; osm_features[i]; ++i) { + keys.insert(osm_features[i], i); } - for (i = 0; osm_icon_mappings[i].value; i++) { - char buff[128]; - - buff[0] = osm_icon_mappings[i].key; - strncpy(&buff[1], osm_icon_mappings[i].value, sizeof(buff) - 1); - - values.insert(QString::fromUtf8(buff), &osm_icon_mappings[i]); + for (int i = 0; osm_icon_mappings[i].value; ++i) { + QPair key(osm_icon_mappings[i].key, osm_icon_mappings[i].value); + values.insert(key, &osm_icon_mappings[i]); } } @@ -438,12 +443,7 @@ osm_feature_ikey(const QString& key) static QString osm_feature_symbol(const int ikey, const char* value) { - char buff[128]; - - buff[0] = ikey; - strncpy(&buff[1], value, sizeof(buff) - 1); - - QString key = QString::fromUtf8(buff); + QPair key(ikey, value); QString result; if (values.contains(key)) { @@ -705,9 +705,8 @@ osm_init_icons() return; } - for (int i = 0; osm_icon_mappings[i].value; i++) { - icons.insert(QString::fromUtf8(osm_icon_mappings[i].icon), - &osm_icon_mappings[i]); + for (int i = 0; osm_icon_mappings[i].value; ++i) { + icons.insert(osm_icon_mappings[i].icon, &osm_icon_mappings[i]); } } -- 2.30.2